import {requsetHttpDetails,reqAddOrUpdateCart} from '@/api'
import {getUUid} from '@/utils/uuid_token'
const state={
    DetailData:{},
    //生成
    UUid_token:getUUid()
}

const actions={
    async getDetailData({commit},skuid){
        let result = await requsetHttpDetails(skuid)
        if(result.code===200){
            commit('GETDETAILDATA',result.data)
        }
    },
    async getaddOrUpdateShopCart({commit},{skuId,skuNum}){
        let result = await reqAddOrUpdateCart(skuId,skuNum)
        if(result.code===200){
            return 'ok'
        }else{
            return Promise.reject(new Error('faile'))
        }
    }
}

const mutations={
    GETDETAILDATA(state,result){
        state.DetailData=result
    }
}

const getters={
    //返回面包屑
    categoryView(state){
        return state.DetailData.categoryView || {}
    },
    //返回手机详情信息
    commodityInfo(state){
        return state.DetailData.skuInfo || {}
    },
    //商品 选项
    spuSaleAttrListInfo(state){
        return state.DetailData.spuSaleAttrList || {}
    }
}

export default{
    state,
    actions,
    mutations,
    getters
}